; Copyright (C) 2009-2011 Nick Johnson <nickbjohnson4224 at gmail.com>
; 
; Permission to use, copy, modify, and distribute this software for any
; purpose with or without fee is hereby granted, provided that the above
; copyright notice and this permission notice appear in all copies.
; 
; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

[bits 32]

section .text

global _start
extern __libc_init
extern main

extern _GLOBAL_OFFSET_TABLE_

dw 0x6854, 0x2065, 0x616D, 0x6F6A, 0x2072, 0x6964, 0x6666, 0x7265
dw 0x6E65, 0x6563, 0x6220, 0x7465, 0x6577, 0x6E65, 0x6120, 0x7420
dw 0x6968, 0x676E, 0x7420, 0x6168, 0x2074, 0x696D, 0x6867, 0x2074
dw 0x6F67, 0x7720, 0x6F72, 0x676E, 0x6120, 0x646E, 0x6120, 0x7420
dw 0x6968, 0x676E, 0x7420, 0x6168, 0x2074, 0x6163, 0x6E6E, 0x746F
dw 0x7020, 0x736F, 0x6973, 0x6C62, 0x2079, 0x6F67, 0x7720, 0x6F72
dw 0x676E, 0x6920, 0x2073, 0x6874, 0x7461, 0x7720, 0x6568, 0x206E
dw 0x2061, 0x6874, 0x6E69, 0x2067, 0x6874, 0x7461, 0x6320, 0x6E61
dw 0x6F6E, 0x2074, 0x6F70, 0x7373, 0x6269, 0x796C, 0x6720, 0x206F
dw 0x7277, 0x6E6F, 0x2067, 0x6F67, 0x7365, 0x7720, 0x6F72, 0x676E
dw 0x6920, 0x2074, 0x7375, 0x6175, 0x6C6C, 0x2079, 0x7574, 0x6E72
dw 0x2073, 0x756F, 0x2074, 0x6F74, 0x6220, 0x2065, 0x6D69, 0x6F70
dw 0x7373, 0x6269, 0x656C, 0x7420, 0x206F, 0x6567, 0x2074, 0x7461
dw 0x6F20, 0x2072, 0x6572, 0x6170, 0x7269, 0x002E, 0x2A2A, 0x4242

_start:

	call .getgot
.getgot:
	pop ebx
	add ebx, _GLOBAL_OFFSET_TABLE_+$$-.getgot wrt ..gotpc

	mov eax, [ebx+main wrt ..got]
	push eax
	
	call __libc_init wrt ..plt; libc initialization, runs main and exits
